package com.jshealthWEB.util;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.primefaces.model.DefaultScheduleEvent;
import org.primefaces.model.LazyScheduleModel;
import org.primefaces.model.ScheduleEvent;

import com.jshealthEJB.bean.EventoAgendaBeanLocal;
import com.jshealthEJB.entidades.EventoAgenda;

public class AgendaLazyModel extends LazyScheduleModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private EventoAgendaBeanLocal eventoAgendaBean;

	private List<EventoAgenda> eventos;

	public AgendaLazyModel(EventoAgendaBeanLocal eventoAgendaBean) {
		this.eventoAgendaBean = eventoAgendaBean;		
	}

	@Override
	public void loadEvents(Date start, Date end) {
		eventos = eventoAgendaBean.consultarEventos(start, end);
		for (EventoAgenda evento : eventos) {
			
			ScheduleEvent event = new DefaultScheduleEvent(evento.getTitulo(),
					evento.getFechaInicio(), evento.getFechaFin(),
					evento.isDiaEntero());
			event.setId(evento.getId()+"");
			addEvent(event);
			
		}
	}
	
	@Override
	public void addEvent(ScheduleEvent event) {
		if(event.getId()==null)
		{
			event.setId(UUID.randomUUID().toString());
		}		
		getEvents().add(event);
	}

}
